<%-- 
    Document   : index
    Created on : 2016-6-28, 12:09:22
    Author     : 52461
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../link.jsp"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="${base}/css/bootstrap-datetimepicker.min.css"/>
        <script type="text/javascript" src="${base}/js/bootstrap-datetimepicker.min.js" ></script>
        <script type="text/javascript" src="${base}/js/bootstrap-datetimepicker.zh-CN.js" ></script>
        <script type="text/javascript" src="${base}/js/LodopFuncs.js" ></script>
        <style>
           .tab{
                margin-left:20px;
                width:500px;
                /*border-collapse:collapse;*/
                /*border:1px dashed;*/
           }/*
           .tab th, .tab td {
                border:1px dashed;
                padding:0px;
           }*/
           .yb{
               float:left;
           }
            .reslut>.table>tbody>tr>td{
                padding-top: 1px;
                padding-bottom: 1px;

            }
            
        </style>
        <title>JSP Page</title>
    </head>
    <body ng-app='hostApp' ng-controller="hostCtrl">
        <div class="hbox hbox-auto-xs hbox-auto-sm ng-scope">
            <div class="col">
                <!--      <div class="wrapper"style="display: table-row;height: 100%;height: 100%">-->
                <table style="width: 100%;height: 100%" >
                    <tr>
                        <td>
                            查询时间:<input type="text" id="datetimepicker" readonly>
                            仪器类型:<select ng-model="deed" ng-options="de.DEVICEMODEL as (de.DEVICEMODEL+de.DEVICENAME) for de in des" ng-change="changeType()" ></select>
                        </td>
                        <td style="height:48px;">
                            <input ng-model="searchContent"  placeholder="病人姓名/病例号" style="width:150px; float: left;margin-left: 20px" class="form-control input-sm" />
                            <button class="btn m-b-xs btn-sm btn-success btn-addon" ng-click="getList()">查询</button>
                            <button class="btn m-b-xs btn-sm btn-info btn-addon" ng-click="plPrint()"><i class="fa fa-print"></i>批量打印</button>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 600px;border-right: 1px solid #dee5e7;">
                            <div style="width:600px;height: 100%;overflow: auto">
                                <table class="table table-bordered" style="width:1500px;overflow-x: hidden;">
                                    <tr>
                                        <th>样本号</th>
                                        <th>姓名</th>
                                        <th>性别</th>
                                        <th>状态</th>
                                        <th>病例号</th>
                                        <th>年龄</th>
                                        <th>类型</th>
                                        <th>科室</th>
                                        <th>审核人</th>
                                        <th>打印时间</th>
                                        <th>仪器类型</th>
                                        <th>检验时间</th>
                                        <th>检验医生</th>
                                    </tr>
                                    <tr ng-repeat="list in lists"  id="do" ng-click="getResult(list,$event)">
                                        <td>{{list.SAMPLENO}}</td>
                                        <td>{{list.PATIENTNAME}}</td>
                                        <td >{{list.SEX}}</td>
                                        <td>{{list.RESULTSTATUS}}</td>
                                        <td>{{list.PATIENTID}}</td>
                                        <td >{{list.AGE}}</td>
                                        <td >{{list.STAYHOSPITALMODE}}</td>
                                        <td >{{list.SECTION}}</td>
                                        <td>{{list.CHECKOPERATOR}}</td>
                                        <td>{{list.PRINTTIME}}</td>
                                        <td>{{list.DEVICEID}}</td>
                                        <td >{{list.MEASURETIME}}</td>
                                        <td >{{list.JYYS}}</td>
                                    </tr>
                                </table>
                                <footer class="panel-heading">
                                    <div class="row">
                                        <div style="text-align: center" >                
                                         <pagination ng-change="pageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="data.currentPage" items-per-page="data.pageSize" total-items="data.bigTotalItems" ng-model="data.bigCurrentPage" max-size="data.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>
                                        </div>
                                    </div>
                                </footer>
                            </div>
                        </td>
                        <td valign="top">
                             
                            <div class="reslut" ng-repeat=" re in results" style="width: 100%;margin-left: 10px;border-left: 1px solid #dee5e7;">
                                <table >
                                    <tr>
                                        <td>项目 :</td>
                                        <td><input  type="text" ng-model="re[$index].EXAMINAIM" style="width: 120px"></td>
                                        <td>科室 :</td>
                                        <td><input type="text" style="width: 120px" ng-model="re[$index].SECTION"></td>
                                        <td>样本 :</td>
                                        <td><input type="text" style="width: 120px" ng-model="re[$index].SAMPLE"></td>
                                        <td><button class="btn m-b-xs btn-sm btn-info btn-addon" ng-click="Print(re)"><i class="fa fa-print"></i>打印</button></td>
                                    </tr>
                                    <tr>
                                        <td>样本号 :</td>
                                        <td><input type="text" style="width: 120px" ng-model="re[$index].SAMPLENO"></td>
                                        <td>检验医生 :</td>
                                        <td><input type="text" style="width: 120px" ng-model="re[$index].JYYS"></td>
                                        <td>检验日期 :</td>
                                        <td><input type="text" style="width: 120px" ng-model="re[$index].MEASURETIME"></td>
                                    </tr>
                                </table>
                            <table class="table table-bordered">
                                <tr id="tr1">
                                    <th>序号</th>
                                    <th>代码</th>
                                    <th>检验项目</th>
                                    <th></th>
                                    <th>结果</th>
                                    <th>单位</th>
                                    <th>范围</th>
                                </tr>
                                <tr ng-repeat="result in re | orderBy: 'index'"  id="dp" ng-class="{true: 'danger', false: 'warning'}[result.isActive]">
                                    <td>{{$index+1}}</td>
                                    <td >{{result.TESTID}}</td>
                                    <td>{{result.CHINESENAME}} </td>
                                    <td style="width:10px;">{{result.HL_STATUS}}</td>
                                    <td>{{result.TESTRESULT}}</td>
                                    <td>{{result.UNIT}}</td>
                                    <td>{{result.fanwei}}</td>
                                </tr>
                            </table>
                            </div>
                        </td>
                    </tr>
                </table>
                <!--</div>-->
            </div>
            <!-- /.col -->            
        </div>
    </body>
</html>
<script>
    angular.module("hostApp", ['baseModule','ui.bootstrap','ui.validate', 'ui.select'])
            .controller("hostCtrl", function ($scope,base) {
                $scope.searchContent="";
                $scope.data = {currentPage: 1};
                $scope.setPage = function (pageNo) {
                    $scope.data.currentPage = pageNo;
                };
                $scope.pageChanged = function () {
                    $scope.getList();
                };
                $scope.data.maxSize = 10;
                $scope.data.bigTotalItems = 20;
                $scope.data.bigCurrentPage = 1;
                $scope.data.pageSize = 10;
                
                
                $scope.changeZt = function (data) {
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].RESULTSTATUS == "0") {
                            data[i].RESULTSTATUS = "无结果"
                        }
                        if (data[i].RESULTSTATUS == "1" || data[i].RESULTSTATUS == null) {
                            data[i].RESULTSTATUS = "未审核";
                        }
                        if (data[i].RESULTSTATUS == "2") {
                            data[i].RESULTSTATUS = "已审核"
                        }
                        if (data[i].RESULTSTATUS == "3") {
                            data[i].RESULTSTATUS = "已打印"
                        }
                    }
                }
                $scope.getList=function(){
                    base.post("select/getList",{pageSize: $scope.data.pageSize, currentPage: $scope.data.currentPage,searchContent:$scope.searchContent}).get( function (data) {

                         $scope.changeZt(data.list);

                        $scope.lists = data.list;
                        
                       
                        $scope.data.bigTotalItems = data.totalRow;
                     });
                 };
                $scope.getList();
                $scope.getDeviceType=function(){
                    $.post("select/getType",function(data){
                        $scope.des=data;
                        $scope.$apply();
                    });
                }
                $scope.getDeviceType();
                
                $scope.changeType=function(){
                    $.post("select/changeType",{pageSize: $scope.data.pageSize, currentPage: $scope.data.currentPage,date:$scope.date,type:$scope.deed},function(data){
                        $scope.changeZt(data.list);
                        $scope.lists = data.list;
                        $scope.data.bigTotalItems = data.totalRow;
                        $scope.$apply();
                    });
                }
//                $scope.selectMatch=function(){
//                     $.post("select/selectMatch",{content:$scope.content},function(data){
//                        $scope.changeZt(data);
//                        $scope.lists=data;
//                        $scope.$apply();
//                    });
//                }
                
                $scope.resulta=[];
                $scope.results=[];
                $scope.getResult = function (item, event) { //获取项目
                    $(event.target).parent().siblings().removeClass("bg-success");
                    $(event.target).parent().addClass("bg-success");
                    $(event.target).removeClass("bg-success");
                    $scope.UUID=item.UUID;
                    $scope.ybh = item.SAMPLENO;
                    $scope.samplepk=item.PK;
                    $scope.sampleNo=item.SAMPLENO;
                    $scope.checkpt=item.RESULTSTATUS;
                    $scope.info=item;
                    $scope.brpk=item.brpk;
//                    $.post("select/getResult", {UUID: item.UUID}, function (data) {
                        $.ajax({
                         type:"post",
                         url:"select/getResult",
                         data:{brpk: item.brpk},
                         async:false,
                         success:function(data){
                        for (var j in data) {
                            for(var i in data[j]){
                            if(!isNaN(data[j][i].TESTRESULT)){
                                if (data[j][i].MREFLO0) {
                                    var lower = data[j][i].MREFLO0;
                                    var hight = data[j][i].MREFHI0;
                                    var lh = lower + "-" + hight;
                                    data[j][i].fanwei = lh;
                                    if (parseFloat(data[j][i].TESTRESULT) < parseFloat(data[j][i].MREFLO0)) {
                                        console.log(data[j][i].TESTRESULT + "   " + data[j][i].MREFLO0);
                                        data[j][i].isActive = true;
                                        data[j][i].HL_STATUS = "↓"
                                    }
                                    if (parseFloat(data[j][i].TESTRESULT) > parseFloat(data[j][i].MREFHI0)) {
                                        data[j][i].isActive = false;
                                        data[j][i].HL_STATUS = "↑"
                                    }
                                }
                                var k = 2;
                                if (data[j][i].Decimalplace) {
                                    k = data[j][i].Decimalplace;
                                }
                                data[j][i].TESTRESULT = parseFloat(data[j][i].TESTRESULT).toFixed(k);
                            }
                        }
                        }
                        
//                         for (var i in data) {
//                                for (var j in $scope.px) {
//                                    if (data[i].ITEMPK == $scope.px[j].TESTPK) {
//                                        if ($scope.px[j].DATA1) {
//                                            console.log(data[i].TESTID);
//                                            data[i].index = parseInt($scope.px[j].DATA1);
//                                        } else {
//                                            data[i].index = 9999;
//                                        }
//                                    }
//                                }
//                            }

//                            data.sort(function (a, b) {
//                                return a.index - b.index;
//                            });
                            $scope.results=data;
//                        $scope.$apply();
                         }
                    })
                    $scope.px=[];
                    for(var i=0;i<$scope.results.length;i++){
                        $.ajax({
                             type:"post",
                             url:"select/getPaixu",
                             data:{devi:$scope.results[i][0].DEVICEID},
                             async:false,
                             success:function(data){
                                 $scope.px.push(data);
                             }
                         });
                    }
                      for(var k in $scope.results){
                        for(var i in $scope.results[k]){
                            for(var j in $scope.px[k]){
                                if($scope.results[k][i].ITEMPK==$scope.px[k][j].TESTPK){
                                    $scope.results[k][i].index=parseInt($scope.px[k][j].DATA1);
                                }
                            }
                        }
                    }  
                    
                        
                        
                };
                        $scope.Print = function (re) {  //打印
                            console.log(re);
                            console.log( $scope.checkpt);
                             if ($scope.checkpt == "已审核" || $scope.checkpt == "已打印") {
                                 var date = new Date().Format("yyyy-MM-dd hh:mm:ss");
                                 base.post("select/printReport",{pk: re[0].samplepk, time: date}).get(function(data){
                                    if (data == "true") {
                                        localStorage.results = JSON.stringify(re);
//                                        localStorage.sampleNo = $scope.sampleNo;
                                        localStorage.date = date;
                                        localStorage.info = JSON.stringify($scope.info);
                                        window.open("printReport-cs.jsp");
                                        
                                    } else {
                                        alert("打印出错");
                                    }
                                 })
                             }else{
                                 steveAl("未审核不能进行打印!", 1000);
                             }
                        }
                        $scope.plPrint=function(){
                            
                            
                            
                        }
                
                
                
              $('#datetimepicker').datetimepicker({
                  language: 'zh-CN',
                  format: 'yyyy-mm-dd ',
                  startView: 3,
                  autoclose: true,
                  minView: 2
                }).on('changeDate', function (ev) {
                    $scope.date=ev.date.Format("yyyy-MM-dd");
                    $.post("select/changeType",{pageSize: $scope.data.pageSize, currentPage: $scope.data.currentPage,date:$scope.date,type:$scope.deed},function(data){

                        $scope.changeZt(data.list);

                        $scope.lists = data.list;
                        $scope.data.bigTotalItems = data.totalRow;
                        $scope.$apply();
                    })
                });        
                
    })
</script>
